<template>
  <div class="person">
    <h1>情况一：监视【ref】定义的【基本类型】数据</h1>
    <h2>当前求和为：{{ sum }}</h2>
    <button @click="changeSum">点我sum+1</button>
  </div>
</template>

<script lang="ts">
export default {
  name: 'Person',
}
</script>

<script lang="ts" setup>
import { ref, reactive, toRefs, toRef,  watch } from 'vue'

// 定义 数据
let sum = ref(0)

function changeSum() {
  sum.value++
}


// 监听数据变化  监视 ref 定义的数据，注意 sum.value 不能监视 ，只能监视 sum
const stop = watch(sum, (newVal, oldVal) => {
  console.log('sum数据被修改了', newVal, oldVal)

  if (newVal >= 10) {
    stop() // 关闭监听
  }
})

</script>

<style scoped>
.person {
  background-color: skyblue;
  box-shadow: 0 0 10px;
  border-radius: 10px;
  padding: 20px;
}

button {
  margin: 0 5px;
}

li {
  font-size: 20px;
}
</style>